package com.ywy.service.impl;

import com.ywy.dao.ResTypeDao;
import com.ywy.entity.ResType;
import com.ywy.service.ResTypeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资源类别Service实现类
 *
 * @author ywy
 * @date 2022/8/17 12:13
 */
@Service
public class ResTypeServiceImpl implements ResTypeService {
    @Resource
    private ResTypeDao resTypeDao;

    @Override
    public List<ResType> listAll() {
        Sort sort = new Sort(Sort.Direction.ASC, "sort");
        return resTypeDao.findAll(sort);
    }

    @Override
    public List<ResType> list(Integer pageNo, Integer pageSize) {
        Pageable pageable = new PageRequest(pageNo - 1, pageSize, Sort.Direction.ASC, "sort");
        Page<ResType> pageResType = resTypeDao.findAll(pageable);
        return pageResType.getContent();
    }

    @Override
    public long getTotal() {
        return resTypeDao.count();
    }

    @Override
    public ResType getById(Integer id) {
        return resTypeDao.findOne(id);
    }

    @Override
    public ResType save(ResType resType) {
        return resTypeDao.save(resType);
    }

    @Override
    public void delete(Integer id) {
        resTypeDao.delete(id);
    }
}
